//引入路由组件
import Home from "@/pages/Home";
import Search from "@/pages/Search";
import Login from "@/pages/Login";
import Register from "@/pages/Register";
import Detail from "@/pages/Detail";
import AddCartSuccess from "@/pages/AddCartSuccess";
import ShopCart from "@/pages/ShopCart";
import Trade from "@/pages/Trade";
import Pay from "@/pages/Pay";
import PaySuccess from "@/pages/PaySuccess";
import Center from "@/pages/Center";
import MyOrder from "@/pages/Center/myOrder";
import GroupBuy from "@/pages/Center/groupOrder";

// 配置路由
export default [
  {
    path: "/center",
    component: Center,
    children: [
      {
        // path: '/center/myorder',
        path: "myorder",
        component: MyOrder,
      },
      {
        path: "groupbuy",
        component: GroupBuy,
      },
      {
        path: "",
        redirect: "myorder",
      },
    ],
  },
  {
    path: "/paysuccess",
    component: PaySuccess,
    meta: { show: true },
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      if (from.path == "/pay" || "/paysuccess") 
         next();
      else {
        //从哪来回哪去
        next(false);
      }
    },
  },
  {
    path: "/pay",
    component: Pay,
    meta: { show: true },
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      if (from.path == "/trade" || "/pay") 
         next();
      else {
        //从哪来回哪去
        next(false);
      }
    },
  },
  {
    path: "/trade",
    component: Trade,
    meta: { show: true },
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      // 在交易页面刷新相当于跳转到 /trade，所以要多加一个判断
      if (from.path == "/shopcart" || "/trade") next();
      else {
        //从哪来回哪去
        next(false);
      }
    },
  },
  {
    path: "/shopcart",
    component: ShopCart,
    name: "shopcart",
    meta: { show: true },
  },
  {
    path: "/addcartsuccess",
    component: AddCartSuccess,
    name: "addcartsuccess",
    meta: { show: true },
  },
  {
    path: "/detail/:skuid?",
    component: Detail,
    meta: { show: true },
  },
  {
    path: "/home",
    component: Home,
    meta: { show: true },
  },
  {
    // params传参需要占位,在后边加一个问号，表示参数可传可不传
    path: "/search/:keyword?",
    component: Search,
    meta: { show: true },
    name: "search",
  },
  {
    path: "/login",
    component: Login,
    meta: { show: false },
  },
  {
    path: "/register",
    component: Register,
    meta: { show: false },
  },
  //重定向
  {
    path: "/",
    redirect: "/home",
  },
];
